import React from 'react'
import PropTypes from 'prop-types'
import {Table} from 'antd'
import AnimTableBody from 'components/DataTable/AnimTableBody'
import {Link} from 'react-router-dom'

const timestampToTime = (timestamp) => {
  let dateObj = new Date(timestamp)
  return dateObj.format('yyyy-qq-dd HH:mm:ss')
}

const List = ({location, isMotion, showDiscoveries, ...tableProps}) => {

  const columns = [
    {
      title: '运营微信号',
      dataIndex: 'operatorWx',
      key: 'operatorWx',
      width: 130,
      render: val => val ? <Link to={''}>{val.wxNo || val.wxId}</Link> : '',
      fixed: 'left',
    },
    {
      title: '微信昵称',
      dataIndex: 'customerWxNickname',
      key: 'customerWxNickname',
      width: 130,
      fixed: 'left',
    },
    {
      title: '归属员工',
      dataIndex: 'operatorWx.belongEmpName',
      key: 'operatorWx_belongEmpName',
      width: 130,
      fixed: 'left',
    },
    {
      title: '公司部门',
      dataIndex: 'operatorWx.deptName',
      key: 'operatorWx_deptName',
    },
    {
      title: '文本内容',
      dataIndex: 'textContent',
      key: 'textContent',
      render: val => val ? val : '图片/视频内容',
      width: 400,
    },
    {
      title: '图片视频链接内容',
      dataIndex: 'mediaContent',
      key: 'mediaContent',
      render: (v, r) => <a href={'javascript:;'} onClick={() => showDiscoveries(r)}>详情</a>,
    },
    {
      title: '点赞数',
      dataIndex: 'pariseNum',
      key: 'pariseNum',
    },
    {
      title: '好友评论数',
      dataIndex: 'commentNum',
      key: 'commentNum',
    },
    {
      title: '回复数',
      dataIndex: 'replyNum',
      key: 'replyNum',
    },
    {
      title: '地理位置',
      dataIndex: 'geoLocation',
      key: 'geoLocation',
      render: val => val ? val : '-',
    },
    {
      title: '发布时间',
      dataIndex: 'releaseTime',
      key: 'releaseTime',
      render: releaseTime => timestampToTime(releaseTime),
    },
    {
      title: '是否删除',
      dataIndex: 'isDelete',
      key: 'isDelete',
      render: val => val === 1 ? '未删除' : '删除',
    },
  ]

  const AnimateBody = (props) => {
    return <AnimTableBody {...props} />
  }

  const CommonBody = (props) => {
    return <tbody {...props} />
  }

  return (
    <Table
      {...tableProps}
      scroll={{x: 1400}}
      columns={columns}
      simple
      rowKey={record => record.id}
      components={{
        body: {wrapper: isMotion ? AnimateBody : CommonBody},
      }}
    />
  )
}

List.propTypes = {
  location: PropTypes.object,
}

export default List
